Bubble Sort Visualization

OVERVIEW


Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order. This algorithm is not suitable for large data sets as its average and worst-case time complexity are quite high.

Time Complexity


  • Best Case: O(n)(if already sorted, only one pass needed).
  • Worst Case: O(n2)(if the array is sorted in reverse order).
  • Space Complexity: O(1)(in-place sorting, no extra space required).

Color Representation


  • Orange → The two elements being compared.
  • Red → Elements still unsorted.
  • Green → Elements that are sorted and in their final position.